//
// Description: 5982. 解决智力问题
// Created by Loading on 2022/1/16.
//

#include <bits/stdc++.h>

using namespace std;

long long mostPoints(vector<vector<int>> &questions) {
    int N = 2 * 1e5 + 10;
    int n = questions.size();
    // dp[i] 表示 解决区间[i, n - 1]内的问题可以获得的最高分数
    vector<long long> dp(N);

    /* 倒序dp */
    /*
     * 跳过：dp[i] = dp[i + 1];
     * 解决，需跳过 questions[i][1] 个问题：dp[i] = questions[i][0] + dp[i + questions[i][1] + 1]
     */
    for (int i = n - 1; i >= 0; --i) {
        dp[i] = max(dp[i + 1], questions[i][0] + dp[i + questions[i][1] + 1]);
    }

    return dp[0];
}

int main() {
    vector<vector<int>> questions = {{1, 1},
                                     {2, 2},
                                     {3, 3},
                                     {4, 4},
                                     {5, 5}};
    auto res = mostPoints(questions);
    cout << res << endl;

    return 0;
}
